// (c) 2015 Teresa Holfeld
package com.holfeld.teresa.vocabtrainer;

import android.content.Intent;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

/**
 * Activity for editing an existing word (vocable pair) or adding a new one.
 *
 * @author Teresa Holfeld, teresa.holfeld@gmail.com
 */
public class EditVocableActivity extends ActionBarActivity {

    private String mVocabularyName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_vocable);

        mVocabularyName = getIntent().getStringExtra(TrainVocabularyFragment.ARG_VOCAB_NAME);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_edit_vocable, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        //noinspection SimplifiableIfStatement
        if (id == android.R.id.home) {
            Intent intent = new Intent(this, VocableListActivity.class);
            intent.putExtra(TrainVocabularyFragment.ARG_VOCAB_NAME, mVocabularyName);
            NavUtils.navigateUpTo(this, intent);
            finish();
            return true;
        } else if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
